// pages/test-mode/test-mode.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    num: 0,
    hour: 30,
    percentage: 100,
    time:30 * 60 * 60 * 1000,
  },

  onTimeChange(val) {
    console.log(val)
    // var { days, hours, minutes, seconds } = val
    var days = val.detail.days
    var hours = val.detail.hours
    var minutes = val.detail.minutes
    var seconds = val.detail.seconds
    console.log(days)
    console.log(hours)
    console.log(minutes)
    console.log(seconds)
    // var totalMilliseconds = (days * 24 * 60 * 60 + hours * 60 * 60 + minutes * 60 + seconds) * 1000

    // var percentage = totalMilliseconds / (this.time * 1000) * 100
    // this.data.percentage = percentage
    // console.log(percentage)
  },

  onChange() {

  },

  getList() {
    wx.request({
      url: 'http://172.20.10.3:3001/questions/randList',
      data: {
        pageSize: 1,
        currentPage: 1
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: (res) => {
        res.data.data.forEach(value => {
          value.options = JSON.parse(value.options)
        })
        this.setData({
          list: res.data.data
        })
      },
    })
  },

  nextQuestion() {
    if (this.data.num < this.data.list.length - 1) {
      this.setData({
        num: this.data.num + 1,
      });
    }
  },

  lastQuestion() {
    if (this.data.num > 0) {
      this.setData({
        num: this.data.num - 1,
      });
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options.mode)
    this.getList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})